Use the Toggle Button Group nodes to allow users to select only one option from a set of options that are mutually exclusive. Toggle buttons in a toggle button group behave like radio buttons, where only one toggle button can be active at a time. Use Toggle Button Group 3D to group 3D toggle buttons in 3D space, and Toggle Button Group 2D to group 2D toggle buttons in 2D space.
A toggle button group is an object that can contain toggle buttons and manages the states of its toggle buttons, but does not provide a visual shape.
To create a toggle button group:
Use brushes to set the background of 2D nodes. In Kanzi all 2D nodes by default have transparent background.
To set the background:
To create a Toggle Button Group 3D object with three toggle buttons:
// Create a Toggle Button Group 3D named Toggle button group and add it to the scene. ToggleButtonGroup3DSharedPtr toggleButtonGroup3D = ToggleButtonGroup3D::create(domain, "Toggle button group"); scene->addChild(toggleButtonGroup3D); // Create a Stack Layout 3D named Stack layout and add it to the Toggle button group. // This stack layout is used only for arranging the items in the Toggle button group. StackLayout3DSharedPtr stackLayout3D = StackLayout3D::create(domain, "Stack layout"); toggleButtonGroup3D->addChild(stackLayout3D); // Create three toggle buttons and add them to the Stack layout. ToggleButton3DSharedPtr buttons[3]; for (kzUint i = 0; i < 3; ++i) { buttons[i] = ToggleButton3D::create(domain, "Toggle button"); // Setting the Button Group Index property to -1, which tells the Toggle button group // to set the index of the toggle button. buttons[i]->setIndexInGroup(-1); stackLayout3D->addChild(buttons[i]); } // Print the index of the toggled button to show that the last button is toggled. std::cout << toggleButtonGroup3D->getCurrentButtonIndex() << endl; // Toggle the first toggle button. buttons[0]->setToggleState(1); // Print the index of the toggled button to show that the first button is toggled. std::cout << toggleButtonGroup3D->getCurrentButtonIndex() << endl;
For details, see the API reference.
To create a Toggle Button Group 2D object with three toggle buttons:
// Create a Toggle Button Group 2D named Toggle button group and add it to the scene. ToggleButtonGroup2DSharedPtr toggleButtonGroup2D = ToggleButtonGroup2D::create(domain, "Toggle button group"); viewportLayer->addChild(toggleButtonGroup2D); // Create a Stack Layout 2D named Stack layout and add it to the Toggle button group. // This stack layout is used only for arranging the items in the Toggle button group. StackLayout2DSharedPtr stackLayout2D = StackLayout2D::create(domain, "Stack layout"); toggleButtonGroup2D->addChild(stackLayout2D); // Create three toggle buttons and add them to the Stack layout. ToggleButton2DSharedPtr buttons[3]; for (kzUint i = 0; i < 3; ++i) { buttons[i] = ToggleButton2D::create(domain, "toggle button"); // Setting the Button Group Index property to -1, which tells the Toggle button group // to set the index of the toggle button. buttons[i]->setIndexInGroup(-1); stackLayout2D->addChild(buttons[i]); } // Print the index of the toggled button to show that the last button is toggled. std::cout << toggleButtonGroup2D->getCurrentButtonIndex() << endl; // Toggle the first toggle button. buttons[0]->setToggleState(1); // Print the index of the toggled button to show that the first button is toggled. std::cout << toggleButtonGroup2D->getCurrentButtonIndex() << endl;
For details, see the API reference.